// components/tabbar-custom/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    selected: {
      type: Number,
      value: 0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    color: '#999999',
    selectedColor: '#496399',
    newsCount: 0, //消息总数
    list: [
      {
        "pagePath": "/pages/index/index",
        "text": "首页",
        "iconPath": "/images/_home.png",
        "selectedIconPath": "/images/home.png"
      },
      {
        "pagePath": "/pages/dongtai/dongtai",
        "text": "清单",
        "iconPath": "/images/_lists.png",
        "selectedIconPath": "/images/lists.png"
      },
      {
        "pagePath": "/pages/user/user",
        "text": "签到",
        "iconPath": "/images/_my.png",
        "selectedIconPath": "/images/my.png"
      }
    ],
    selected: 0,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset;
      const url = data.path;
      console.log(data.index);
      if(data.index == 1 || data.index == 2){
        if(wx.getStorageSync('userId')){
          wx.switchTab({url});
          return;
        }else {
          wx.navigateTo({
            url: `/pages/login/login?index=${data.index}`,
          });
          return ;
        }
      }
      // 自定义一个事件，并且传值
      //this.triggerEvent('myevent',{key: 1});
      wx.switchTab({url});
    },
  }
})
